{include file="buy/header.tpl"}


<!-- 头部// -->


<!-- start: Content -->
<div id="content" class="span12">


<div class="row-fluid">


<div class="box span12"><!-- Default panel contents -->



<div class="box-content span12">{include file="buy/admintop.tpl"}

<div class="form-inline" method="post" action="./index.php?order/search">

<input type="button" class="btn btn-default" value="合并"
	onclick="merge()"> <select name="type" class="input-small" id="key">
	<option value="id">流水号</option>
	<option value="orderno">订单号</option>
	<option value="shr" selected>收货人</option>

</select>
<div class="input-append"><input class="form-control" name="value"
	id="value" placeholder="搜索全部订单" type="text">
<button class="btn btn-warning" type="submit" onclick="search()"><i
	class="icon-search"></i></button>
</div>
流水线:{foreach from=$status key=key item=l}<a
	href="./index.php?buyorder/listing/?status={$key}" {if $key==$s}class=
	"label label-warning"{/if}
	>{$l}</a>|{/foreach} <a href="javascript:daochu()" class="icon-print">
导出</a></div>
<table class="table table-hover">
	<tr class=title>
		<th class="span1">流水号</th>
		<th class="span1">状态</th>
		<th class="span2">下单时间</th>
		<th class="span3">订单名称</th>
		<th class="span1">件数</th>
		<th class="span2">收货人</th>

		<th class="span1">总金额</th>

		<th class="span3">备注</th>
		<th class="span2">操作</th>
	</tr>




	{foreach from=$order item=l}
	<tr id="{$l.id}">
		<td><label class="checkbox"> <input type="checkbox" name="id"
			value="{$l.id}"></input> {$l.id} </label></td>

		<td id="zs_{$l.orderno}">{if $l.status=="等待审核"}<span
			class="label label-warning">{$l.status}</span>{else if
		$l.status=="关闭"}<span class="label label-default">{$l.status}</span>{else}<span
			class="label label-success">{$l.status}</span>{/if}</td>
		<td>{$l.add_time|wtime}</td>


		<td><a href="javascript:remark('{$l.orderno}')" title="备注"><i
			class="icon-edit"></i></a> <a
			href="javascript:detail('{$l.orderno}')">{$l.name}</a></td>
		<td id="num{$l.id}">{$l.num}</td>
		<td><a
			href="./index.php?buyorder/search/?key=shr&value={$l.real_name}">{$l.real_name}</a></td>

		<td id="money{$l.id}">{$l.money}</td>
		<td><span id="remark_{$l.orderno}">{$l.remark}</span></td>

		<td id="zt_{$l.orderno}">{if $l.status=="等待审核"}
		<div class="btn-group" id="{$l.orderno}">
		<button type="button" class="btn btn-default"
			onclick="setStatus('{$l.orderno}',1,{$l.id})">确认</button>
		<button type="button" class="btn btn-default dropdown-toggle"
			data-toggle="dropdown"><span class="caret"></span> <span
			class="sr-only"></span></button>
		<ul class="dropdown-menu" role="menu">
			<li><a href="javascript:setStatus('{$l.orderno}',-1,{$l.id})"><i
				class="icon-remove"></i>关闭</a></li>
		</ul>
		</div>

		{elseif $l.status=="审核通过"}
		<button type="button" class="btn btn-default"
			onclick="setStatus('{$l.orderno}',2,{$l.id})">确认</button>


		{/if} {$l.action_name}</td>
	</tr>
	{/foreach}

</table>
<input type="hidden" name="maxid" id="maxid" value="{$maxid}"> <input
	type="hidden" name="status" id="status" value="{$s}">

<div class="pagination pagination-centered">
<ul id="pager"></ul>
</div>

</div>




</div>



<script src="./static/public/layer/layer.min.js"></script> <script
	src="./static/public/layer/extend/layer.ext.js"></script> {literal} <script
	type='text/javascript'>
 $(document).ready(function(){

   $("#value").keyup(function(){
      if(event.which==13){
        search();
          }
	   })
	 })
function getorder(){
var status=$("#status").val();
var maxid=$("#maxid").val();

	$.post("./index.php?buyrobot/getneworder",{id:maxid,status:status},function(data){
  
  
var id=Math.floor(Math.random()*1000);
id="wl"+id;
      var con="<tr id=\""+id+"\"><td></td><td><span class=\"label label-important\">机器人瓦力</span></td><td colspan=\"7\">"+data.message+"</td></tr>";
$(".title").after(con);
if(data.status==false||status==0){
  $("#"+id).hide(30000);
	}
$("#maxid").val(maxid);
		},"json")
}

window.setInterval(getorder,60000);
 
function search(){

	var key=$("#key").val();
	var value=$("#value").val();
   location.href="./index.php?buyorder/search/?key="+key+"&value="+value;
	
}


 
function merge(){
	 var arrChk=$("input[name='id']:checked");
	 var ids=new Array();
$(arrChk).each(function(){
    ids.push(this.value);                        
 }); 
if(ids.length<2){

	alert("请选择至少2个订单");
	return false;
}
$.post("./index.php?buyorder/merge",{ids:ids},function(data){
   if(data.status==true){
   alert(data.message);
   var rs=data.data;
   removeorder(ids,rs.id,rs.money,rs.num);
   }else{
   alert(data.message);
	   }
	},"json")

}

function removeorder(ids,id,money,num){
for(var i=1;i<ids.length;i++){

	$("#"+ids[i]).remove();
}
$("#money"+id).html(money);
$("#num"+id).html(num);
}

function detail(sno){
$.layer({
    type: 2,
    shadeClose: true,
    title: false,
    closeBtn: [0, true],
    shade: [0.3, '#000'],
    border: [0],
    offset: ['20px',''],
    area: ['1000px', ($(window).height() - 50) +'px'],
    iframe: {src: './index.php?buyorderinfo/edit/?sno='+sno,
        scrolling: 'yes'
         }
}) 
}

function remark(orderno){
	var con=$("#remark_"+orderno).html();
var t=	layer.prompt({title: '订单备注',type:3,val:con}, function(name){

        if(name.length<1){
             return false;
         }
		
	    $.post("./index.php?buyorder/remark",{remark:name,orderno:orderno},function(data){

	    	  if(data.status==true){
                $("#remark_"+orderno).html(name);
                  layer.close(t);
		      }else{
		       alert(data.message);
		      }
	    },"json")
	});
	}

function daochu(){
var t=	layer.prompt({title: '起始流水号',type:0}, function(name){

        if(name.length<1){
             return false;
         }
        layer.close(t);
		location.href="./index.php?buyorder/export/?id="+name;
	});
	}


function setStatus(orderno,status,id){
	$.post("./index.php?buyorder/setstatus",{orderno:orderno,status:status},function(data){

		if(data.status==false){
	alert(data.message);
	return;
		}
	if(status==1){
	$("#zs_"+orderno).html("<span class='label label-success'>成功</span>");
	}

		$("#"+id).remove();
		
	if(status==-1){
		$("#zs_"+orderno).html("<span class='label label-default'>关闭</span>");

	}

	},"json")
	}


var options = {
		currentPage: {/literal}{$num.current}{literal},
		totalPages: {/literal}{$num.page}{literal},
		numberOfPages:5,
		bootstrapMajorVersion:3,
		pageUrl: function(type, page, current){
		    return './index.php?buyorder/listing/?&status={/literal}{$s}{literal}&p='+page;
		}
		}
		$('#pager').bootstrapPaginator(options);


</script> {/literal} {include file="news/footer.tpl"}